package com.java.comprehensive.arithmetic.leecode.tags.array;

import util.QuickSort;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @program: comprehensive-service
 *
 * @description: 寻找两个正序数组的中心位
 *
 * @author: 窦绍飞
 *
 * @create: 2021-12-07 16:11
 **/
public class LeetCode_04 {

	public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
		int[] temp = new int[nums1.length + nums2.length];

		System.arraycopy(nums1, 0, temp, 0, nums1.length);
		System.arraycopy(nums2, 0, temp, nums1.length, nums2.length);
		Arrays.sort(temp);
		double i = 0d;
		if (temp.length % 2 == 0) {
			i = temp[temp.length / 2] + temp[temp.length / 2 - 1];
			return i / 2;
		} else {
			int falg = temp.length / 2;
			return temp[falg];
		}

	}

	public static void main(String[] args) {
		int[] nums = { 1, 8, 6, 2, 5, 4, 8, 3, 7 };
		int[] nums2 = { 3, 4 };
		double medianSortedArrays = findMedianSortedArrays(nums, nums2);
		System.out.println(medianSortedArrays);
	}
}
